import smtplib
from email.mime.text import MIMEText
from email.header import Header

mail_server = "smtp.163.com"   # 服务器：imap/smtp
Port_number = 465  # SSL端口：465或587或25（无协议）
mail_user = "wyh2085195880@163.com"     # 邮箱用户名
mail_pwd = "KNEMUTGQFDHORHPE"   # 授权码
sender = "wyh2085195880@163.com"    # 发送者邮箱账号名
receivers = [sender, "2085195880@qq.com"]  # 接收者
message = MIMEText("测试报告测试邮件", "html", "utf-8")  # 文本信息
message['From'] = Header(sender, "utf-8")  # 发件人名称
message['To'] = Header("receiver", "utf-8")    # 收件人名称
message['Subject'] = Header('提交信息', 'utf-8')  # 标题信息（类似gitee的提交信息）

try:
    smtpObj = smtplib.SMTP_SSL(mail_server, Port_number)
    # 标识用户身份
    # smtpObj.helo(mail_server)
    # 返回结果确认
    # smtpObj.ehlo(mail_server)
    smtpObj.login(mail_user, mail_pwd)  # 登录
    smtpObj.sendmail(sender, receivers, message.as_string())  # 发送人，接收人，文本信息
    print("邮件发送成功")
    smtpObj.quit()
except smtplib.SMTPException:
    print("Error：无法发送邮件")

